/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2025-01-09
 * Time: 10:46
 */
class Solution7 {
    public boolean isPalindrome(String s) {
        if(s == "") return true;
        //先转化为纯的字符串
        int len = s.length();
        StringBuilder builder = new StringBuilder();
        for(int i = 0 ; i < len ; i++){
            char ch = s.charAt(i);
            if((ch >= 'a' && ch <='z') || (ch >= 'A' && ch <='Z') || (ch >= '0' && ch <='9') ){
                builder.append(ch);
            }
        }
        String str = builder.toString().toLowerCase();
        int n = str.length();
        int left = 0 , right = n-1;
        while(left >= 0 && right <= n-1){
            if(n % 2 == 0){
                left = (0 + n - 1)/2;
                right = left+1;
                while(left >= 0 && right <= n-1){
                    if(str.charAt(left) == str.charAt(right)){
                        left--;
                        right++;
                    }else{
                        return false;
                    }
                }
            }

            if(n % 2 == 1){
                left = (0 + n - 1)/2;;
                right = left;
                while(left >= 0 && right <= n-1){
                    if(str.charAt(left) == str.charAt(right)){
                        left--;
                        right++;
                    }else{
                        return false;
                    }
                }
            }
        }
        return true;
    }
}
public class Test7 {
}
